Cleanup Zeroable and ZeroableOptions.#118
Open
mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
Open
Conversation
Place definitions and implementations (incl. macro invocations) of the `Zeroable` trait first in the relevant section of `src/lib.rs`, followed by the ZeroableOption trait and its implementations. Rename `impl_non_zero_int_zeroable_option` to `impl_zeroable_option` for consistency. This commit should not introduce any functional changes. Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Improve impl_zeroable_option macro to handle generic impls for types like `&T`, `&mut T`, `NonNull<T>`, and others (for which `Option<T>` is guaranteed to be zeroable) with similar approach to `impl_zeroable`. Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Minimal testing including: - add `tests/zeroing.rs` coverage that `zeroed::<Option<T>>()` is `None` for refs, `NonNull`, and nonzero ints. - add generic compile-check coverage for `T: ZeroableOption` (`&u8`, `&mut u8`, `NonNull<u8>`, `NonZeroU8`). - add UI compile-fail test `zeroable/option_string_not_zeroable.rs` to verify `Option<String>` is not `Zeroable`. Not entirely sure how useful these tests are but it's on a different commit so feel free to not include them. Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did my part of janitor work to help cleanup
ZeroableandZeroableOptionas suggested in #116:Zeroabletrait and its implementations (including macro invocations) first in the relevant section ofsrc/lib.rs, followed by theZeroableOptiontrait and its implementations.impl_non_zero_int_zeroable_option; it should be renamed toimpl_zeroable_optionfor consistency.impl_zeroable_optionmacro to handle generic impls for types like&T,&mut T,NonNull<T>, and others (for whichOption<T>is guaranteed to be zeroable).Added an extra commit for minimal testing which I'm not sure how helpful it is but feel free to not include:
tests/zeroing.rscoverage thatzeroed::<Option<T>>()isNonefor refs,NonNull, and nonzero ints.T: ZeroableOption(&u8,&mut u8,NonNull<u8>,NonZeroU8).zeroable/option_string_not_zeroable.rsto verifyOption<String>is notZeroable.Closes: #116